<script>
  import config from './config'
  import store from '@/store'
  import {
    getToken
  } from '@/utils/auth'

  export default {
    onLaunch: function() {
      this.initApp()
      //新增
      this.globalData.SystemInfo = uni.getSystemInfoSync();
    },
    globalData: {
      getModel: function() {
        //获取手机型号
        return wx.getSystemInfoSync()["model"];
      },
      getVersion: function() {
        //获取微信版本号
        return wx.getSystemInfoSync()["version"];
      },
      getSystem: function() {
        //获取操作系统版本
        return wx.getSystemInfoSync()["system"];
      },
      getPlatform: function() {
        //获取客户端平台
        return wx.getSystemInfoSync()["platform"];
      },
      getSDKVersion: function() {
        //获取客户端基础库版本
        return wx.getSystemInfoSync()["SDKVersion"];
      },
      userInfo: null,
      platform: "",
      screenWidth: uni.getSystemInfoSync().screenWidth,
      screenHeight: uni.getSystemInfoSync().screenHeight,
      BLEInformation: {
        platform: "",
        deviceId: "",
        writeCharaterId: "",
        writeServiceId: "",
        notifyCharaterId: "",
        notifyServiceId: "",
        readCharaterId: "",
        readServiceId: ""
      },

      //新增的
      buf2hex: function(buffer) {
        return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
      },
      buf2string: function(buffer) {
        var arr = Array.prototype.map.call(new Uint8Array(buffer), x => x);
        var str = '';
        console.log(buffer)
        for (var i = 0; i < arr.length; i++) {
          str += String.fromCharCode(arr[i]);
        }
        return str;
      },
      Str2Bytes(str) {
        var pos = 0;
        var len = str.length;
        if (len % 2 != 0) {
          return null;
        }
        len /= 2;
        var hexA = new Array();
        for (var i = 0; i < len; i++) {
          var s = str.substr(pos, 2);
          var v = parseInt(s, 16);
          hexA.push(v);
          pos += 2;
        }
        return hexA;
      },

      SystemInfo: {}
    },
    methods: {
      // 初始化应用
      initApp() {
        // 初始化应用配置
        this.initConfig()
        // 检查用户登录状态
        //#ifdef H5
        this.checkLogin()
        //#endif
      },
      initConfig() {
        this.globalData.config = config
        this.globalData.sysinfo = uni.getSystemInfoSync();
      },
      checkLogin() {
        if (!getToken()) {
          this.$tab.reLaunch('/pages/login')
        }
      }
    }
  }
</script>

<style lang="scss">
  @import '@/static/scss/index.scss'
</style>